package com.wsecar.sharelogin.wx.core;

import android.content.Context;

import com.tencent.mm.opensdk.constants.Build;
import com.tencent.mm.opensdk.modelpay.JumpToOfflinePay;
import com.tencent.mm.opensdk.openapi.IWXAPI;
import com.tencent.mm.opensdk.openapi.WXAPIFactory;

public class WxLoginImpl {
    private IWXAPI api;

    /**
     * 初始化时必须要先注册
     * @param context
     * @param wxAppId
     */
    public void  registerAppToWx(Context context, String wxAppId){
        if (null == api){
            api = WXAPIFactory.createWXAPI(context, wxAppId, false);
        }
        api.registerApp(wxAppId);
    }

    /**
     * 离线支付
     */
    public void jumpToOfflinePay(){
        if (null != api){
            int wxSdkVersion = api.getWXAppSupportAPI();
            if (wxSdkVersion >= Build.OFFLINE_PAY_SDK_INT) {
                api.sendReq(new JumpToOfflinePay.Req());
            }
        }
    }

}
